<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2020/7/21
 * Time: 15:39
 */

namespace App\HttpController\Admin;
use App\Services\AdminGroupService;
use App\Services\ReponseCodeService;
use EasySwoole\Validate\Validate;

class AdminGroup extends AdminBaseController
{
    /**
     * showdoc
     * @catalog 后台/角色管理
     * @title  添加角色
     * @description 添加角色
     * @method POST
     * @url /admin/adminGroup
     * @param group_name  是 string 分组名字
     * @param status 是 int 是否启用：0未启用，1启用
     * @return_param  code int 状态码(200:成功0:失败400:参数错误)
     * @return_param  group_name 用户名
     * @return_param  status 真实姓名
     * @return_param  created_at 创建时间
     * @return_param  updated_at更新时间
     */
    public function createAdminGroup(){
        $admin = $this->adminInfo;
        $param =  $this->param;
        $valitor = new Validate();
        $valitor->addColumn('group_name', 'group_name')->required('group_name is require');
        $valitor->addColumn('status', 'status')->required('status is require')->numeric('status should be numeric');
        $bool = $valitor->validate($param);
        if(!$bool){
            return $this->writeJson(ReponseCodeService::CODE_BAD_REQUEST, null, $valitor->getError()->__toString());
        }
        $adminGroupService = new AdminGroupService();
        $ret = $adminGroupService->createGroup($param,$admin);
        return $this->writeJson($ret, $ret, '');
    }
}